<template>
    <div>
        <el-table :data="menulist" border style="width: 100%" row-key="id" :tree-props="{ chidren: 'children' }">
            <el-table-column prop="id" label="菜单编号" width="180">
            </el-table-column>
            <el-table-column prop="title" label="菜单名称" width="180">
            </el-table-column>
            <el-table-column prop="pid" label="上级菜单" width="180">
            </el-table-column>
            <el-table-column  label="菜单图标" width="180">
                <template slot-scope="item">
                    <div>
                        <i :class="item.row.icon"></i>
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="url" label="菜单地址">
            </el-table-column>
            <el-table-column label="状态" width="180">
                <template slot-scope="item">
                    <div>
                        {{ item.row.status == 1 ? '启用' : '禁用' }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="操作" width="180">
                <template slot-scope="item">
                    <div>
                        <el-button type="primary" size="mini" @click="edit(item.row.id)">编辑</el-button>
                        <el-button type="danger" icon="el-icon-delete" circle size="mini"
                            @click="del(item.row.id)"></el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script>
// 辅助性函数
import { mapGetters, mapActions } from "vuex";
import { menuDelete } from "@/request/api";
export default {
    data() {
        return {

        }
    },
    computed: {
        ...mapGetters({
            menulist: 'menu/getMenu'
        })
    },
    mounted() {
        // console.log(this.$store)
        this.getMenuList()
    },
    methods: {
        ...mapActions({
            getMenuList: 'menu/getMenuListAciton'
        }),
        // 封装一个删除事件
        del(id) {
            this.$confirm('你确定要删除吗？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: "warning"
            }).then(() => {
                // 调用删除接口
                menuDelete({
                    id
                }).then(res => {
                    if (res.code == 200) {
                        this.$message.success(res.msg)
                        // 重新调用
                        this.getMenuList()
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                })
            })
        },
        // 编辑
        edit(id) {
            // 告诉父组件打开弹窗
            this.$emit('edit', id)
        }
    }
}
</script>
<style scoped></style>